<template>
  <div class="sendMessages">
    <div class="sendMessagesContent">
      <div class="messagesbox">
        <!--短信模板的选择-->
        <div class="selectmessages">
          <div class="smsbox fl">
            <el-button v-for="item in btnOptions" :key="item.id" @click="tepBtn(item.id, item.name)">
              <icon-svg style="float: left;margin-right: 3px;" :name="item.icon || ''"></icon-svg>
              <span>{{item.name}}</span>
            </el-button>
          </div>
          <div class="fr">
            <span>
              剩余短信
              <i class="bigfonts" id="shulixns">{{ smsCunts }}</i>
              条
            </span>
            <a class="buymessages _g_hiddenAgents _g_hiddenAgents_show" @click="getsmsGuiGeLists()" href="javascript:;"
              style="">【购买短信】</a>
          </div>
        </div>
        <!--短信模板的选择-->

        <!--短信的内容-->
        <div class="messagescontens">
          <el-input type="textarea" maxlength="500" :rows="5" placeholder="请输入内容" v-model="sendVal"></el-input>
          <!-- <textarea class="form-control" name="smscontent" id="smscontent" placeholder="请填写短信内容...">{{sendVal}}</textarea> -->
          <div class="messagesinfo">
            <div class="fl">
              <span>
                短信签名【
                <i class="shopname">{{ sendName ? sendName : '暂未设置' }}</i>
                】
              </span>
              <el-button size="mini" round @click="sendNameBtn">设置</el-button>
            </div>
            <div class="fr">
              <span>
                在70个字的基础上每加67个字 按
                <i id="tiao">1</i>
                条计费
                ,当前字数：
                <i id="tiao">{{sendVal.length + (sendName ? sendName.length : '暂未设置'.length) + '[]退订回T'.length}}</i>
                ,按
                <i id="tiao" style="color: red;">{{tiaoshu(sendVal.length + (sendName ? sendName.length : '暂未设置'.length) + '[]退订回T'.length)}}</i>
                条收费
              </span>
            </div>
            <!-- <div class="fr wordcountbox">
              <span>当前还可以输入<i class="wordcount" id="number">55</i>个字</span>
            </div> -->
          </div>
        </div>
        <!--短信的内容-->

        <!--添加发送的会员-->
        <div class="sendmember" style="padding-top: 12px;">
          <div class="sendmemberlist" id="sendmemberlist" @click="selUser()">
            <i class="el-icon-plus" title="选择会员"></i>
            <!-- <i class="addsendmessages icon-plus" title="选择会员" id="addsendmessages"></i> -->
            <span style="line-height: 30px;" v-show="showUser.checkSelLists.length <= 0">选择会员</span>
            <i v-for="item in showUser.checkSelLists" :key="item.id" :title="item.name">{{ item.name ? item.name.substr(0, 1) : '--' }}</i>
          </div>
          <div class="sendmembercounts">
            <span>
              已经选择
              <i class="counts" id="memberListCounts">{{ showUser.checkSelLists.length }}</i>
              位
            </span>
          </div>
        </div>
        <!--添加发送的会员-->
        <!-- 号码框 -->
        <div class="messagescontens">
          <el-input type="textarea" :rows="4" placeholder="请输入号码以','分隔多个号码" v-model="showUser.sendTel"></el-input>
        </div>
        <div style="margin-top: 12px;">
          <el-button @click="filterNumberBtn">过滤重号</el-button>
          <el-button @click="filterErrorNumberBtn">过滤错号</el-button>
          <el-upload style="display: inline-table;margin-left: 10px;" class="upload-demo" ref="upload" :action="txt_import_url()"
            :file-list="fileList" :on-success="txt_importsuccess" :before-upload="txt_import" :with-credentials="true"
            :show-file-list="false">
            <el-button slot="trigger">TXT导入</el-button>
          </el-upload>
          <el-upload style="display: inline-table;margin-left: 10px;" class="upload-demo" ref="upload" :action="excel_import_url()"
            :file-list="fileList" :on-success="txt_importsuccess" :before-upload="excel_import" :with-credentials="true"
            :show-file-list="false">
            <el-button slot="trigger">EXCEL导入</el-button>
          </el-upload>
        </div>

        <!--发送短信按钮-->
        <div class="sendbox-btn">
          <div class="fl">
            <el-tooltip class="item" effect="dark" placement="top-start">
              <el-checkbox v-model="checked2">同意短信发送条款</el-checkbox>
              <p slot="content" class="tooltip-content" v-html="smsxieyi">
                <!-- {{smsxieyi}} -->
                <!--                <ul>
                  <li style="margin-bottom: 6px;">不利用短信平台制作、复制、发布、传播含有下列内容的信息：</li>
                  <li>1、反对宪法所确定的基本原则的；</li>
                  <li>2、危害国家安全，泄露国家秘密，颠覆国家政权，破坏国家统一的；</li>
                  <li>3、损坏国家荣誉和利益的；</li>
                  <li>4、煽动民族仇恨、民族歧视，破坏民族团结的；</li>
                  <li>5、破坏国家民族宗教政策，宣扬邪教和封建迷信的；</li>
                  <li>6、散布谣言，扰乱社会秩序，破坏社会稳定的；</li>
                  <li>7、散布淫秽、色情、赌博、暴力、凶杀、恐怖或者教唆犯罪的；</li>
                  <li>8、侮辱或者诽谤他人，侵害他人合法权益的；</li>
                  <li>9、含有法律、行政法规禁止的其他内容的；</li>
                </ul> -->
              </p>
            </el-tooltip>
          </div>
          <button type="button" @click="sendSMSBtn()" class="btn sendmessage-btn" id="sendems_Btn">发送</button>
          <!-- <button type="button" class="btn clickperview">点击预览</button> -->
        </div>
        <!--发送短信按钮-->
      </div>

      <!--短信发送的规则-->
      <div class="messagestips">
        <ul>
          <li>短信预报：活动，销售推广类产品要必须加退订回T，并使用自己的店铺签名发送短信</li>
          <li>达到时间：测试短信30分钟左右，群发短信1小时25分钟左右</li>
          <li>短信内容：必须正规合法</li>
          <li id="messagestipsverify_distributor_id" style="">如有未收到的情况，请48小时内及时联系客服QQ：343767992</li>
        </ul>
        <!-- <div class="testmessage">
          <ul>
            <li>测试短信发送 :</li>
            <li>
              <el-input v-model="testPhone" placeholder="请输入手机号"></el-input>
            </li>
            <li>
              <button type="button" class="btn testsend-btn" id="btnTestSendSms" @click="testSMSBtn()">发送</button>
            </li>
          </ul>
        </div> -->
      </div>
      <!--短信发送的规则-->
      <div class="share-container paycenterpage">
        <!--选择购买的版本-->
        <div class="showAlert" v-show="buyShop.showBuyAlert" v-loading="buyShop.payingLoading">
          <div class="alertHeader">
            <p style="line-height: 50px;">购买短信包</p>
            <i class="el-icon-close" @click="(buyShop.showBuyAlert = !buyShop.showBuyAlert), (zhezhao = false)"></i>
          </div>
          <div class="main">
            <div class="shareinfo">
              <div class="sharleft"><span>选择规格 :</span></div>
            </div>
            <el-tag v-show="buyShop.PayNumber">{{ buyShop.counts }}</el-tag>
            <ul class="smsMain" id="buySmsMain" v-show="!buyShop.PayNumber">
              <el-radio-group v-model="buyShop.counts" @change="buyguigeChange">
                <el-radio-button v-for="item in smsGuiGeLists" :key="item.id" :label="item.counts + ',' + item.money">{{ item.counts }}条/{{ item.money }}元</el-radio-button>
              </el-radio-group>
            </ul>
            <div class="shareinfo" v-show="buyShop.PayNumber">
              <div class="sharleft"><span>订单单号 :</span></div>
            </div>
            <el-tag v-show="buyShop.PayNumber">{{ buyShop.PayNumber }}</el-tag>
          </div>

          <!--支付方式-->
          <div class="paystyle">
            <div class="shareinfo" v-show="buyShop.PayNumber">
              <div class="sharleft"><span>支付方式 :</span></div>
            </div>
            <div class="shareinfo" v-show="buyShop.PayNumber">
              <div class="selectpaystyle">
                <el-radio v-model="buyShop.payType" label="wxpay" border>微信</el-radio>
                <!-- <el-radio v-model="buyShop.payType" label="alipay" border>支付宝</el-radio> -->
              </div>
            </div>
            <div class="shopnumber-pay">
              <div class="paybtnbox fr">
                <input type="hidden" id="sms_ordenum" value="1350" />
                <span class="pay-money">
                  实付金额 :
                  <i class="money">¥</i>
                  <i class="money" id="pay">{{ buyShop.money }}</i>
                </span>
                <!-- 立即下单-->
                <button type="submit" class="btn successbtn" id="btnPay" @click="buySMSCounts" v-show="!buyShop.PayNumber">立即下单</button>
                <button type="submit" class="btn" v-show="!buyShop.PayNumber" @click="(buyShop.showBuyAlert = !buyShop.showBuyAlert), (zhezhao = false)">取消</button>
                <!-- 立即支付-->
                <button type="submit" class="btn successbtn" id="btnPay" @click="buySMSpay" v-show="buyShop.PayNumber">立即支付</button>
                <button type="submit" class="btn" v-show="buyShop.PayNumber" @click="cancelOrder">取消订单</button>
              </div>
            </div>
          </div>
        </div>
      </div>

      <!-- 二维码窗体 -->
      <div class="showAlert2" v-show="paymsg">
        <div id="qrcode" ref="qrcode"></div>
        <p>{{ paymsg }}</p>
        <p style="height: 16px;color: red;">{{ paymsg2 }}</p>
        <el-button type="primary" @click="searchOrderRul">查询订单</el-button>
        <el-button @click="canlcePay">取消支付</el-button>
      </div>
    </div>

    <!-- 预览区-->
    <div class="messagesPreview">
      <div class="previewtitle">预览区</div>
      <div class="preview">
        <div class="viewcontent" id="wordcountbox">
          <p class="messagestext" id="messagestext" style="text-align: justify;text-justify: newspaper;word-break: break-all;">【{{ sendName ? sendName : '暂未设置' }}】{{ sendVal }}
            退订回T</p>
          <i id="signature"></i>
        </div>
      </div>
    </div>

    <!-- 遮罩 -->
    <div class="zezhao" v-show="zhezhao"></div>
    <!-- 选择模板弹框 -->
    <div class="showAlert" v-show="showAlert">
      <div class="alertHeader">
        <p style="line-height: 50px;">{{ showAlertName }}</p>
        <i class="el-icon-close" @click="(showAlert = !showAlert), (zhezhao = !zhezhao)"></i>
      </div>
      <div class="alertCon">
        <p v-show="showAlertOptions.length <= 0">暂无短信模板</p>
        <el-tabs v-model="activeName" v-show="showAlertOptions.length > 0">
          <el-tab-pane v-for="item in showAlertOptions" :key="item.id" :label="item.name" :name="item.name + item.id">
            <ul class="selUserUl">
              <li v-for="item2 in item.childrenCons" :key="item2.id">
                <el-radio v-model="showAlertVal" :label="item2.content">{{ item2.content }}</el-radio>
              </li>
            </ul>
          </el-tab-pane>
        </el-tabs>
      </div>
      <div class="btnBox" style="position: absolute;bottom: 18px;right: 28px;">
        <el-button type="success" size="small" icon="el-icon-check" v-show="showAlertOptions.length > 0" @click="subVal()">确定</el-button>
        <el-button icon="el-icon-close" size="small" @click="(showAlert = !showAlert), (zhezhao = !zhezhao)">取消</el-button>
      </div>
    </div>

    <!-- 选择用户弹框 -->
    <div class="showAlert" v-show="showUser.alert">
      <div class="alertHeader">
        <p style="line-height: 50px;">选择会员</p>
        <i class="el-icon-close" @click="(showUser.alert = !showUser.alert), (zhezhao = !zhezhao)"></i>
      </div>
      <div class="alertCon">
        <el-form :inline="true" :model="showUser.dataForm" @keyup.enter.native="getDataList()">
          <el-form-item>
            <el-input v-model="showUser.dataForm.name" placeholder="姓名" clearable></el-input>
          </el-form-item>
          <el-form-item>
            <el-input v-model="showUser.dataForm.mobile" placeholder="手机号" clearable></el-input>
          </el-form-item>
          <el-form-item>
            <!--            <el-select v-model="showUser.dataForm.gender" placeholder="请选择">
              <el-option v-for="item in sexOptions" :key="item.value" :label="item.label" :value="item.value"></el-option>
            </el-select> -->
            <!--            <el-radio v-model="showUser.dataForm.gender" label="">默认</el-radio>
            <el-radio v-model="showUser.dataForm.gender" label="1">男</el-radio>
              <el-radio v-model="showUser.dataForm.gender" label="2">女</el-radio> -->
          </el-form-item>
          <el-form-item>
            <el-button @click="getDataList()">{{ $t('Common.Query') }}</el-button>
          </el-form-item>
          <!--        <el-button v-if="isAuth('hotel:thotelsmshistory:save')" type="primary" @click="addOrUpdateHandle()">{{ $t('Common.Insert') }}</el-button>
            <el-button v-if="isAuth('hotel:thotelsmshistory:delete')" type="danger" @click="deleteHandle()" :disabled="dataListSelections.length <= 0">{{ $t('Common.BulkDelete') }}</el-button>
          </el-form-item> -->
        </el-form>
        <el-table ref="multipleTable" :data="showUser.lists" tooltip-effect="dark" style="width: 100%;height: 100%;"
          @selection-change="handleSelectionChange">
          <el-table-column type="selection" width="55"></el-table-column>
          <el-table-column prop="name" header-align="center" align="center" label="姓名">
            <template slot-scope="scope">
              <span v-if="scope.row.name">{{ scope.row.name }}</span>
              <span v-else>--</span>
            </template>
          </el-table-column>

          <el-table-column prop="tel" header-align="center" align="center" width="150" label="手机">
            <template slot-scope="scope">
              <span v-if="scope.row.tel">{{ scope.row.tel }}</span>
              <span v-else>--</span>
            </template>
          </el-table-column>
          <el-table-column prop="gender" header-align="center" align="center" label="性别">
            <template slot-scope="scope">
              <span>{{ scope.row.gender == '0' ? '男' : '女' || '--' }}</span>
            </template>
          </el-table-column>
          <el-table-column prop="levelName" header-align="center" align="center" label="会员类型">
            <template slot-scope="scope">
              <span v-if="scope.row.levelName">{{ scope.row.levelName }}</span>
              <span v-else>--</span>
            </template>
          </el-table-column>
        </el-table>
      </div>
      <!-- 筛选条件 -->
      <div class="btnBox" style="position: absolute;bottom: 18px;left: 28px;">
        <el-checkbox class="btnBox_display btnBox_checkbox" @change="getDataList()" v-model="showUser.dataForm.sendedChecked"
          style="margin-right: 0px;"></el-checkbox>
        过滤
        <el-input class="btnBox_display btnBox_input" v-model="showUser.dataForm.sendedDay" @input="getDataList()" size="small"></el-input>
        天内发送过的会员
        <el-checkbox style="margin-left: 28px;" @change="getDataList()" class="btnBox_display btnBox_checkbox" v-model="showUser.dataForm.xiaoshouChecked"></el-checkbox>
        过滤
        <el-input class="btnBox_display btnBox_input" v-model="showUser.dataForm.xiaoshouDay" @input="getDataList()"
          size="small"></el-input>
        天内销售过的会员
      </div>
      <div class="btnBox" style="position: absolute;bottom: 18px;right: 28px;">
        <el-button type="success" size="small" icon="el-icon-check" v-show="showUser.lists.length > 0" @click="subUserVal()">确定({{ showUser.selLists.length }})</el-button>
        <el-button icon="el-icon-close" size="small" @click="(showUser.alert = !showUser.alert), (zhezhao = !zhezhao)">取消</el-button>
      </div>
    </div>
  </div>
</template>

<script>
  import $ from 'jquery';
  import QRCode from 'qrcode2';
  export default {
    components: {
      QRCode
    },
    data() {
      return {
        smsCunts: 0,
        testPhone: '',
        btnOptions: [],
        checked2: false,
        zhezhao: false,
        showAlert: false,
        showAlertName: '',
        showAlertOptions: [],
        showAlertVal: '',
        activeName: 'first',
        sendVal: '',
        showUser: {
          alert: false,
          lists: [],
          selLists: [],
          counts: 0,
          checkSelLists: [],
          sendTel: '',
          dataForm: {
            mobile: '',
            name: '',
            sendedChecked: true,
            sendedDay: 5,
            xiaoshouChecked: true,
            xiaoshouDay: 5
          }
        },
        buyShop: {
          payType: 'wxpay',
          counts: '1350,100',
          showBuyAlert: false,
          money: 100,
          PayNumber: '',
          payingLoading: false
        },
        paymsg: '',
        paymsg2: '',
        smsGuiGeLists: [],
        //定时器
        searchOrderTimer: '',
        searchPayOrderTimer: '',
        fileList: [],
        textData: '',
        sendName: '',
        smsxieyi: ''
      };
    },
    activated() {
      this.xieyiContent();
      this.btnOptionsMenu();
      this.searchSMSCounts();
    },
    methods: {
      //条数算法
      tiaoshu(num) {
        //在70个字的基础上每加67个字 按1条计费
        if (num <= 70) {
          return 1
        }
        num = num - 70
        return Math.ceil(num / 67) + 1
      },
      xieyiContent() {
        this.$http({
          url: this.$http.adornUrl(`/hotel/hotelprotocol/info/5`),
          method: 'get',
          params: this.$http.adornParams({
            id: 5
          })
        }).then(({
          data
        }) => {
          if (data && data.code === 0) {
            this.smsxieyi = data.hotelProtocol.content;
          }
        });
      },
      qrcodeScan(width, height, text) {
        //生成二维码
        $('#qrcode').html('');
        let qrcode = new QRCode('qrcode', {
          width: width, // 二维码宽度
          height: height // 二维码高度
        });
        qrcode.makeCode(text);
      },
      //设置签名
      sendNameBtn() {
        this.$prompt('请输入需要重新设置的签名', '提示', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            inputPattern: /\S/,
            inputErrorMessage: '不可为空',
            closeOnClickModal: false
          })
          .then(({
            value
          }) => {
            this.$http({
              url: this.$http.adornUrl(`/hotel/thotelsmscounts/set_sendName`),
              method: 'get',
              params: this.$http.adornParams({
                sendName: value
              })
            }).then(({
              data
            }) => {
              if (data && data.code === 0) {
                this.searchSMSCounts();
                this.$message({
                  type: 'success',
                  message: '你的新签名是: ' + value
                });
              } else {
                this.$message({
                  type: 'error',
                  message: data.msg
                });
              }
            });
          })
          .catch(() => {
            this.$message({
              type: 'info',
              message: '已取消设置'
            });
          });
      },
      ///查询支付结果
      searchOrderRul() {
        //发起请求
        this.$http({
          url: this.$http.adornUrl('/hotel/thotelsmspayorder/pay_result'),
          method: 'get',
          params: this.$http.adornParams({
            ...this.buyShop
          })
        }).then(({
          data
        }) => {
          if (data && data.code === 0) {
            this.paymsg = '';
            this.searchSMSCounts();
            this.buyShop.showBuyAlert = false;
            this.buyShop.payingLoading = false;
            this.zhezhao = false;
            this.$message({
              type: 'success',
              message: data.msg
            });
            if (this.searchOrderTimer) {
              clearInterval(this.searchOrderTimer); //关闭
            }
          } else {
            this.paymsg2 = data.msg;
          }
        });
      },
      //取消订单
      cancelOrder() {
        let that = this;
        this.zhezhao = false;
        this.buyShop.showBuyAlert = false;
        //确认弹框
        this.$confirm('将取消当前订单, 是否继续?', '提示', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'warning'
          })
          .then(() => {
            //发起请求
            this.$http({
              url: this.$http.adornUrl('/hotel/thotelsmspayorder/cancel_order'),
              method: 'get',
              params: this.$http.adornParams({
                ...this.buyShop
              })
            }).then(({
              data
            }) => {
              if (data && data.code === 0) {
                this.$message({
                  type: 'success',
                  message: data.msg
                });
                this.buyShop.PayNumber = '';
                this.searchSMSCounts();
                if (this.searchPayOrderTimer) {
                  clearInterval(this.searchPayOrderTimer); //关闭
                }
              } else {
                this.$message({
                  type: 'info',
                  message: data.msg
                });
                this.zhezhao = true;
                this.buyShop.showBuyAlert = true;
              }
            });
          })
          .catch(() => {
            this.zhezhao = true;
            this.buyShop.showBuyAlert = true;
          });
      },
      // 立即支付
      buySMSpay() {
        let that = this;
        this.$http({
          url: this.$http.adornUrl('/hotel/thotelsmspayorder/place_an_pay'),
          method: 'get',
          params: this.$http.adornParams({
            ...this.buyShop
          })
        }).then(({
          data
        }) => {
          if (data && data.code === 0) {
            this.buyShop.payingLoading = true;
            console.log(data.pay_code);
            this.qrcodeScan(200, 200, data.pay_code);
            switch (this.buyShop.payType) {
              case 'wxpay':
                this.paymsg = '请使用微信扫描上方二维码';
                break;
            }
            this.searchOrderTimer = setInterval(() => {
              this.searchOrderRul();
            }, 2000);
          } else {
            this.$message({
              type: 'info',
              message: data.msg
            });
          }
        });
      },
      //取消支付
      canlcePay() {
        //取消当前支付
        this.$http({
          url: this.$http.adornUrl('/hotel/thotelsmspayorder/cancel_pay'),
          method: 'get',
          params: this.$http.adornParams({
            ...this.buyShop
          })
        }).then(({
          data
        }) => {
          if (data && data.code === 0) {
            this.buyShop.PayNumber = data.order;
          }
        });
        this.paymsg = '';
        this.buyShop.payingLoading = false;
        this.paymsg2 = '';
        if (this.searchOrderTimer) {
          clearInterval(this.searchOrderTimer); //关闭
        }
      },
      //查询短信包订单
      latel_ynot_pay() {
        //检测本地是否有订单号
        if (this.buyShop.PayNumber) {
          //存在
          this.$http({
            url: this.$http.adornUrl('/hotel/thotelsmspayorder/real_time_order'),
            method: 'get',
            params: this.$http.adornParams({
              ...this.buyShop
            })
          }).then(({
            data
          }) => {
            if (data && data.code === 0) {
              if (data.entity.state == 1) {
                this.buyShop.money = data.entity.payMoney;
                this.buyShop.counts = data.entity.counts + '条/' + data.entity.money + '元';
              } else {
                this.buyShop.PayNumber = '';
              }
            }
          });
        } else {
          this.$http({
            url: this.$http.adornUrl('/hotel/thotelsmspayorder/latel_ynot_pay'),
            method: 'get',
            params: this.$http.adornParams({})
          }).then(({
            data
          }) => {
            if (data && data.code === 0) {
              this.buyShop.counts = data.entity.counts + '条/' + data.entity.money + '元';
              this.buyShop.money = data.entity.payMoney;
              this.buyShop.PayNumber = data.entity.payNumber;
            }
          });
        }
      },
      //购买短信按钮触发
      getsmsGuiGeLists() {
        let that = this;
        this.buyShop.showBuyAlert = !this.buyShop.showBuyAlert;
        this.zhezhao = true;
        this.$http({
          url: this.$http.adornUrl('/hotel/thotelsmspayguige/guige_list'),
          method: 'get',
          params: this.$http.adornParams({
            page: 0,
            limit: 999
          })
        }).then(({
          data
        }) => {
          if (data && data.code === 0) {
            that.smsGuiGeLists = data.page.list;
            that.buyShop.counts = that.smsGuiGeLists[0].counts + ',' + that.smsGuiGeLists[0].money;
            if (!that.buyShop.PayNumber) {
              that.buyShop.money = that.smsGuiGeLists[0].money;
            }
            this.latel_ynot_pay();
            this.searchPayOrderTimer = setInterval(() => {
              this.latel_ynot_pay();
            }, 2000);
          } else {
            that.smsGuiGeLists = [];
          }
        });
      },
      buyguigeChange(value) {
        var arr = value.split(',');
        this.buyShop.money = arr[1];
      },
      buySMSCounts() {
        this.$http({
          url: this.$http.adornUrl('/hotel/thotelsmspayorder/place_an_order'),
          method: 'get',
          params: this.$http.adornParams({
            ...this.buyShop
          })
        }).then(({
          data
        }) => {
          if (data && data.code === 0) {
            this.$message({
              type: 'success',
              message: '下单成功，请尽快支付'
            });
            this.buyShop.PayNumber = data.PayNumber;
            var arr = this.buyShop.counts.split(',');
            this.buyShop.counts = arr[0] + '条/' + arr[1] + '元';
          } else {
            this.$message({
              type: 'info',
              message: '下单失败'
            });
          }
        });
      },
      //获取会员数据
      getDataList() {
        let that = this;
        // 获取会员数据
        this.$http({
          url: this.$http.adornUrl('/hotel/hotelmemberleveldetail/sms_sel_user'),
          method: 'get',
          params: this.$http.adornParams({
            page: 0,
            limit: 999,
            ...this.showUser.dataForm
          })
        }).then(({
          data
        }) => {
          if (data && data.code === 0) {
            that.showUser.lists = data.page.records
            that.showUser.lists.forEach((item, index) => {
              console.log(!item.tel)
              if (!item.tel) {
                that.showUser.lists.splice(that.showUser.lists.indexOf(index), 1);
              }
              console.log(that.showUser.lists)
            })
          } else {
            this.$message({
              type: 'error',
              message: data.msg
            });
          }
        });
      },
      testSMSBtn() {
        let that = this;
        //检测是否输入店铺签名
        var testName = that.sendName;
        console.log(testName);
        if (!that.sendName) {
          this.$message({
            type: 'info',
            message: '请先设置店铺签名'
          });
          this.sendNameBtn();
          return false;
        }
        //是否勾选协议
        if (!that.checked2) {
          this.$message({
            type: 'info',
            message: '请勾选短信发送协议'
          });
          return false;
        }
        if (!that.testPhone) {
          this.$message({
            type: 'info',
            message: '请输入测试手机号'
          });
          return false;
        }
        //是否输入内容
        if (that.sendVal == '') {
          this.$message({
            type: 'info',
            message: '请输入发送内容'
          });
          return false;
        }
        //检测发送数量
        var counts1 = Math.ceil(that.sendVal.length / 67);
        if (that.smsCunts == 0 || that.smsCunts - counts1 < 0) {
          this.$message({
            type: 'error',
            message: '您的短信数量不够了！'
          });
          return false;
        }

        this.$http({
          url: this.$http.adornUrl('/hotel/thotelsmscounts/sendSMS'),
          method: 'get',
          params: this.$http.adornParams({
            tels: that.testPhone,
            sendVal: '【' + that.sendName + '】' + '这是测试内容'
          })
        }).then(({
          data
        }) => {
          if (data && data.code === 0) {
            that.smsCunts = that.smsCunts - 1;
            this.$message({
              type: 'success',
              message: data.msg
            });
          } else {
            this.$message({
              type: 'error',
              message: data.msg
            });
          }
        });
      },
      sendSMSBtn() {
        let that = this;
        this.filterNumberBtn();
        this.filterErrorNumberBtn();
        //检测是否输入店铺签名
        var testName = that.sendName;
        console.log(testName);
        if (!that.sendName) {
          this.$message({
            type: 'info',
            message: '请先设置店铺签名'
          });
          this.sendNameBtn();
          return false;
        }
        //是否勾选协议
        if (!that.checked2) {
          this.$message({
            type: 'info',
            message: '请勾选短信发送协议'
          });
          return false;
        }
        //是否输入手机号码或选择会员
        if (that.showUser.sendTel == '') {
          this.$message({
            type: 'info',
            message: '请输入手机号码或选择会员'
          });
          return false;
        }
        //是否输入内容
        if (that.sendVal == '') {
          this.$message({
            type: 'info',
            message: '请输入发送内容'
          });
          return false;
        }
        //检测发送数量
        var counts1 = this.tiaoshu(that.sendName.length + that.sendVal.length + '[]退订回T'.length)
        console.log(counts1);
        var telArr = that.showUser.sendTel.split(',');
        console.log(telArr.length * counts1);
        if (that.smsCunts == 0 || that.smsCunts - telArr.length * counts1 < 0) {
          this.$message({
            type: 'error',
            message: '您的短信数量不够了！'
          });
          return false;
        }
        //确认弹框
        this.$confirm('确认发送短信, 是否继续?', '提示', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'warning'
          })
          .then(() => {
            //检测发送数量
            that.sendSMS();
          })
          .catch(() => {
            this.$message({
              type: 'info',
              message: '已取消发送'
            });
          });
      },
      sendSMS() {
        let that = this;
        let sendVal = '【' + that.sendName + '】' + that.sendVal + '退订回T';
        this.$http({
          url: this.$http.adornUrl('/hotel/thotelsmscounts/sendSMS'),
          method: 'get',
          params: this.$http.adornParams({
            tels: that.showUser.sendTel,
            sendVal: sendVal
          })
        }).then(({
          data
        }) => {
          if (data && data.code === 0) {
            this.searchSMSCounts();
            this.$message({
              type: 'success',
              message: data.msg
            });
          } else {
            this.$message({
              type: 'error',
              message: data.msg
            });
          }
        });
      },
      handleSelectionChange(val) {
        let that = this;
        that.showUser.selLists = val;
        console.log(val);
      },
      // 选择会员确认按钮
      subUserVal() {
        let that = this;
        if (that.showUser.selLists.length <= 0) {
          window.alert('请选择会员');
          return false;
        }
        that.showUser.counts = that.showUser.selLists.length;
        that.showUser.checkSelLists = that.showUser.selLists;
        //将手机号添加到框框里
        var checkSelLists = that.showUser.selLists;
        var telStr = '';
        for (var i = 0; i < checkSelLists.length; i++) {
          var entity = checkSelLists[i];
          telStr += entity.tel + ',';
        }
        telStr = telStr.substr(0, telStr.length - 1);
        if (that.showUser.sendTel) {
          var lastStr = that.showUser.sendTel.charAt(that.showUser.sendTel.length - 1);
          if (lastStr != ',') {
            that.showUser.sendTel = that.showUser.sendTel + ',';
          }
        }
        that.showUser.sendTel = that.showUser.sendTel + telStr;
        that.showUser.alert = false;
        that.zhezhao = false;
      },
      //过滤重号
      filterNumberBtn() {
        let that = this;
        var arr = that.showUser.sendTel.split(',');
        var sendTel = [...new Set(arr)];
        var telStr = '';
        sendTel.map(i => {
          telStr += i + ',';
        });
        that.showUser.sendTel = telStr.substr(0, telStr.length - 1);
      },
      //过滤错号
      filterErrorNumberBtn() {
        let that = this;
        //过滤
        var arr = that.showUser.sendTel.split(',');
        var arr2 = [];
        var mobile_mode = /^1[3|4|5|7|8][0-9]{9}$/;
        arr.map(i => {
          if (mobile_mode.test(i)) {
            arr2.push(i);
          }
        });
        //重新放回
        var telStr = '';
        arr2.map(i => {
          telStr += i + ',';
        });
        that.showUser.sendTel = telStr.substr(0, telStr.length - 1);
      },
      //text文件导入路径
      txt_import_url() {
        return this.$http.adornUrl(`/hotel/thotelsmscounts/txt_import`);
      },
      // excel文件导入路径
      excel_import_url() {
        return this.$http.adornUrl(`/hotel/thotelsmscounts/excel_import`);
      },
      //excel导入格式判断
      excel_import(file) {
        console.log(file);
        var type = file.type;
      },
      //txt导入格式判断
      txt_import(file) {
        var type = file.type;
        if (type != 'text/plain') {
          this.$message({
            type: 'error',
            message: '请选择正确的txt文档'
          });
          return false;
        }
      },
      //txt回调
      txt_importsuccess(response, file, fileList) {
        let that = this;
        if (response && response.code === 0) {
          if (that.showUser.sendTel) {
            var lastStr = that.showUser.sendTel.charAt(that.showUser.sendTel.length - 1);
            if (lastStr != ',') {
              that.showUser.sendTel = that.showUser.sendTel + ',';
            }
          }
          this.showUser.sendTel = this.showUser.sendTel + response.tels;
          this.$message({
            type: 'success',
            message: response.msg
          });
        } else {
          this.$message({
            type: 'error',
            message: response.msg
          });
        }
      },
      selUser() {
        let that = this;
        that.showUser.alert = true;
        that.zhezhao = true;
        // 获取会员数据
        that.getDataList();
      },
      subVal() {
        let that = this;
        if (that.showAlertVal == '') {
          window.alert('请选择短信模板');
          return false;
        }
        that.sendVal = that.showAlertVal;
        that.showAlert = false;
        that.zhezhao = false;
      },
      tepBtn(id, name) {
        console.log(id);
        let that = this;
        that.zhezhao = true;
        that.showAlert = true;
        that.showAlertName = name;
        this.$http({
          url: this.$http.adornUrl(`/hotel/thotelsmstemplatemenu/tepBtn_search`),
          method: 'get',
          params: this.$http.adornParams({
            page: 0,
            limit: 999,
            father_id: id,
            state: 1
          })
        }).then(({
          data
        }) => {
          if (data && data.code === 0) {
            if (data.list.length > 0) {
              that.showAlertOptions = data.list;
              let entity = that.showAlertOptions[0];
              that.activeName = entity.name + entity.id;
            } else {
              that.showAlertOptions = [];
            }
          }
        });
      },
      btnOptionsMenu() {
        this.$http({
          url: this.$http.adornUrl(`/hotel/thotelsmstemplatemenu/list`),
          method: 'get',
          params: this.$http.adornParams({
            page: 0,
            limit: 999,
            fatherId: 0
          })
        }).then(({
          data
        }) => {
          if (data && data.code === 0) {
            this.btnOptions = data.page.records;
          }
        });
      },
      searchSMSCounts() {
        this.$http({
          url: this.$http.adornUrl(`/hotel/thotelsmscounts/searchSMSCounts`),
          method: 'get',
          params: this.$http.adornParams({})
        }).then(({
          data
        }) => {
          if (data && data.code === 0) {
            this.smsCunts = data.entity.counts;
            this.sendName = data.entity.sendName;
          } else {
            this.smsCunts = 0;
          }
        });
      }
    },
    mounted: function() {
      setInterval(() => {
        this.btnOptionsMenu();
        this.searchSMSCounts();
      }, 3000);
    },
  };
</script>

<style>
  .sendMessages ol,
  ul {
    list-style: none;
    /* padding-left: 0px; */
    padding: 0px;
    margin: 0px;
  }

  .sendMessages .selUserUl li {
    padding-top: 10px;
    padding-bottom: 10px;
    padding-right: 5px;
    line-height: 25px;
    border-bottom: 1px solid #e5e5e5;
    font-size: 12px;
    position: relative;
    cursor: pointer;
  }

  .sendMessages .sendMessagesContent {
    width: 71.941177%;
    float: left;
    margin-right: 1%;
    padding-bottom: 20px;
    max-width: 800px;
  }

  .sendMessages .messagesbox {
    padding-right: 30px;
    padding-bottom: 15px;
    background-color: #fff;
    width: 100%;
  }

  .sendMessages .selectmessages {
    width: 100%;
    margin-top: 10px;
    height: 54px;
    overflow: hidden;
    line-height: 34px;
  }

  .sendMessages .selectmessages .smsbox {
    color: #fff;
  }

  .fl {
    float: left;
  }

  .sendMessages .selectmessages .exclusive {
    background-color: #f66;
  }

  .sendMessages .selectmessages button {
    margin-right: 15px;
  }

  .btn {
    display: inline-block;
    padding: 6px 12px;
    margin-bottom: 0;
    font-size: 14px;
    font-weight: 400;
    line-height: 1.42857143;
    text-align: center;
    white-space: nowrap;
    vertical-align: middle;
    -ms-touch-action: manipulation;
    touch-action: manipulation;
    cursor: pointer;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
    background-image: none;
    border: 1px solid transparent;
    border-radius: 4px;
  }

  .pad {
    padding-left: 2px;
    padding-right: 2px;
  }

  .fr {
    float: right;
  }

  .sendMessages .sendmember {
    height: 54px;
    width: 100%;
  }

  .sendMessages .sendmember .sendmemberlist {
    float: left;
    max-width: 450px;
    height: 30px;
    overflow: hidden;
    cursor: pointer;
  }

  .sendMessages .sendmember .sendmemberlist .addsendmessages {
    cursor: pointer;
  }

  .sendMessages .sendmember .sendmemberlist i {
    width: 30px;
    height: 30px;
    text-align: center;
    font-style: normal;
    line-height: 30px;
    display: block;
    border: 1px dashed #a5a5a5;
    border-radius: 50%;
    -webkit-border-radius: 50%;
    -ms-border-radius: 50%;
    -moz-border-radius: 50%;
    color: #666;
    float: left;
    margin-right: 8px;
  }

  .sendMessages .sendmember .sendmembercounts {
    float: right;
    line-height: 30px;
    padding-right: 5px;
  }

  .sendMessages .sendmember .sendmembercounts .counts {
    color: #31c17b;
    font-size: 20px;
    padding: 0 3px;
  }

  .sendMessages .messagescontens {
    width: 100%;
    overflow: hidden;
    border-radius: 4px;
    -webkit-border-radius: 4px;
    -ms-border-radius: 4px;
    -moz-border-radius: 4px;
    position: relative;
  }

  .sendMessages .messagescontens textarea {
    display: block;
    width: 100%;
    background-color: #f3f3f3;
    -webkit-border-radius: 4px 4px 0 0;
    -ms-border-radius: 4px 4px 0 0;
    -moz-border-radius: 4px 4px 0 0;
  }

  .sendMessages .messagescontens .messagesinfo {
    width: 100%;
    height: 50px;
    bottom: 0;
    left: 0;
    right: 0;
    background-color: #bdc5c1;
    line-height: 50px;
    color: #fff;
    padding-left: 20px;
    padding-right: 20px;
  }

  .sendMessages .messagescontens .messagesinfo .wordcountbox {
    margin-right: 15px;
  }

  .sendMessages .sendbox-btn {
    width: 100%;
    height: 58px;
    padding-top: 15px;
    padding-bottom: 10px;
  }

  .sendMessages .sendbox-btn .agree {
    width: 14px;
    height: 14px;
    line-height: 16px;
    display: inline-block;
    background-color: #f66;
    font-size: 12px;
    text-align: center;
    color: #fff;
    border-radius: 3px;
    -webkit-border-radius: 3px;
    -ms-border-radius: 3px;
    -moz-border-radius: 3px;
  }

  .sendMessages .sendbox-btn .sendmessage-btn {
    background-color: #f66;
    color: #fff;
    float: right;
    padding-left: 20px;
    padding-right: 20px;
  }

  .sendMessages .messagestips {
    width: 100%;
    background-color: #fff;
  }

  .sendMessages .messagestips ul {
    padding-left: 0px;
    width: 100%;
  }

  .sendMessages .messagestips ul li {
    line-height: 30px;
    font-size: 14px;
  }

  .colorff {
    color: #f00;
  }

  .sendMessages .messagestips .testmessage {
    padding-top: 20px;
  }

  .sendMessages .messagestips .testmessage ul {
    width: 420px;
    overflow: hidden;
  }

  .sendMessages .messagestips .testmessage ul li {
    float: left;
    margin-right: 15px;
  }

  .sendMessages .messagestips ul li {
    line-height: 30px;
    font-size: 14px;
  }

  .form-control {
    display: block;
    width: 100%;
    height: 34px;
    padding: 6px 12px;
    font-size: 14px;
    line-height: 1.42857143;
    color: #555;
    background-color: #fff;
    background-image: none;
    border: 1px solid #ccc;
    border-radius: 4px;
    -webkit-box-shadow: none;
    box-shadow: none;
    -webkit-transition: none;
    -o-transition: none;
    transition: none;
  }

  .paycenterpage {
    width: 100%;
    margin: auto;
    max-width: 1100px;
  }

  .paycenterpage .main {
    width: 100%;
    padding-top: 20px;
    padding-left: 30px;
    padding-right: 30px;
    padding-bottom: 10px;
    margin-bottom: 12px;
    background-color: #fff;
  }

  .paycenterpage .smsMain {
    overflow: hidden;
  }

  .paycenterpage .smsMain li {
    float: left;
    width: 25%;
    padding: 10px;
  }

  .paycenterpage .smsMain li a {
    color: #666;
    display: block;
    transition: 0.35s;
  }

  .paycenterpage .smsMain li a img {
    width: 35%;
  }

  .paycenterpage .smsMain li a img {
    float: left;
    position: relative;
    transition: 0.35s;
  }

  .paycenterpage .smsMain li a .smsbox_ {
    float: left;
    padding: 0 5px;
  }

  .paycenterpage .smsMain li a .smsbox_ p {
    line-height: 30px;
    position: relative;
  }

  .paycenterpage .smsMain li a .selectpicee {
    position: absolute;
    right: 0;
    top: 8px;
    font-size: 16px;
    color: #999;
  }

  .paycenterpage .paystyle {
    width: 100%;
    padding-top: 20px;
    padding-left: 30px;
    padding-right: 30px;
    padding-bottom: 10px;
    background-color: #fff;
  }

  .paycenterpage .shareinfo {
    overflow: hidden;
    line-height: 38px;
    margin-bottom: 12px;
  }

  .paycenterpage .paystyle .sharleft {
    height: 38px;
  }

  .paycenterpage .shareinfo .sharleft {
    width: 90px;
    float: left;
  }

  .paycenterpage .shareinfo {
    overflow: hidden;
    line-height: 38px;
    margin-bottom: 12px;
  }

  .paycenterpage .paystyle .shopnumber-pay {
    width: 100%;
    line-height: 30px;
    padding-top: 10px;
    padding-bottom: 10px;
    height: 80px;
  }

  .paycenterpage .paystyle .shopnumber-pay .paybtnbox {
    padding-top: 15px;
  }

  .paycenterpage .paystyle .shopnumber-pay .paybtnbox .pay-money {
    margin-right: 25px;
    line-height: 34px;
  }

  .paycenterpage .paystyle .shopnumber-pay .paybtnbox .money {
    font-size: 20px;
    color: #ff5400;
  }

  .paycenterpage .paystyle .shopnumber-pay .paybtnbox #pay {
    font-size: 30px;
    font-weight: bold;
    font-family: '宋体';
  }

  .paycenterpage .paystyle .shopnumber-pay .paybtnbox .successbtn {
    padding-left: 20px;
    padding-right: 20px;
    background-color: #f66;
    color: #fff;
  }

  .sendMessages .showAlert {
    width: 50vw;
    height: 60vh;
    position: fixed;
    top: calc((100vh - 60vh) / 2);
    left: calc((100vw - 50vw) / 2);
    background: white;
    z-index: 999999;
    box-shadow: 1px 1px 50px rgba(0, 0, 0, 0.3);
    border-radius: 2px;
  }

  .sendMessages .showAlert2 #qrcode {
    text-align: center;
    width: 200px;
    margin: 0px auto;
    margin-top: 18px;
  }

  .sendMessages .showAlert2 {
    width: 300px;
    height: 340px;
    position: fixed;
    top: calc((100vh - 340px) / 2);
    left: calc((100vw - 300px) / 2);
    background: white;
    z-index: 9999999;
    box-shadow: 1px 1px 50px rgba(0, 0, 0, 0.3);
    border-radius: 2px;
    text-align: center;
  }

  .sendMessages .zezhao {
    position: fixed;
    top: 0px;
    left: 0px;
    width: 100%;
    height: 100%;
    z-index: 99999;
    background-color: #000;
    opacity: 0.6;
    filter: alpha(opacity=60);
  }

  .sendMessages .showAlert .alertHeader {
    text-align: center;
  }

  .sendMessages .showAlert .alertHeader p {
    display: inline-table;
  }

  .sendMessages .showAlert .alertHeader i {
    float: right;
    display: inline-table;
    font-size: 22px;
    line-height: 40px;
    margin-right: 8px;
    cursor: pointer;
  }

  .alertCon {
    width: 96%;
    margin: 0px auto;
    height: 60%;
  }

  .sendMessages .messagesPreview {
    width: 27.058823%;
    height: 570px;
    float: left;
    padding-top: 20px;
  }

  .sendMessages .messagesPreview .previewtitle {
    height: 34px;
    line-height: 34px;
    text-align: center;
  }

  .sendMessages .messagesPreview .preview {
    width: 270px;
    height: 516px;
    margin: auto;
    position: relative;
    background: url(./images/perview.png) no-repeat;
    background-size: 100% 100%;
  }

  .sendMessages .messagesPreview .preview .viewcontent {
    position: absolute;
    top: 110px;
    width: 200px;
    min-height: 30px;
    padding: 5px;
    font-size: 12px;
    left: 0;
    right: 0;
    margin: auto;
    background-color: #fff;
    border-radius: 3px;
    -webkit-border-radius: 3px;
    -ms-border-radius: 3px;
    -moz-border-radius: 3px;
  }

  .sendMessages .testsend-btn {
    background-color: #f66;
    color: #fff;
    float: right;
    padding-left: 20px;
    padding-right: 20px;
  }

  .btnBox .btnBox_display {
    display: inline-table;
  }

  .btnBox .btnBox_checkbox {}

  .btnBox .btnBox_input {
    width: 80px;
  }
</style>
